//
//  NavigationViewController.swift
//  yueshijia
//
//  Created by 王磊 on 17/4/18.
//  Copyright © 2017年 王磊. All rights reserved.
//

import UIKit

class NavigationViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            viewController.navigationItem.leftBarButtonItem = self.itemWithTArget(target: self, action: #selector(back), image: "nav_return_normal", hightImage: "nav_return_normal")
        }
        super.pushViewController(viewController, animated: animated)
    }
    func back() {
        self.popViewController(animated: true)
    }
    func more() {
        self.popToRootViewController(animated: true)
    }
    func itemWithTArget(target: Any,action: Selector, image: String,hightImage: String) -> UIBarButtonItem {
        let btn = UIButton.init(type: .custom)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        btn.setBackgroundImage(UIImage.init(named: image), for: .normal)
        btn.setBackgroundImage(UIImage.init(named: hightImage), for: .highlighted)
        //
        btn.frame.size = (btn.currentBackgroundImage?.size)!
        
        return UIBarButtonItem.init(customView: btn)
    }

}
